// js将数字转换成万、亿、万亿
function numberFormat(data) {
  var value = Number(data);
  let unit = "";
  var k = 10000,
    sizes = ["", "万", "亿", "万亿"],
    i;
  if (value < k) {
    value = value;
  } else {
    i = Math.floor(Math.log(value) / Math.log(k));
    value = (value / Math.pow(k, i)).toFixed(2);
    unit = sizes[i];
  }
  let num = 0;

  data ? (num = value + unit) : (num = 0);
  return num;
}

function isNumberStr(str) {
  return /^[+-]?(0|([1-9]\d*))(\.\d+)?$/g.test(str);
}

module.exports = {
  numberFormat,
  isNumberStr,
};
